package cn.com.blackboard.SISIntergrationBiz.controller;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cm.com.blackboard.DataModule4B2.customizeConfigUtils.ExtentionAttributeUtil;
import cn.com.blackboard.DataModule4B2.BBDataUtils.LocaleUtil;
import cn.com.blackboard.DataModule4B2.util.ExtentionModel;
  
@Controller
@RequestMapping("/extention")
public class ExtentionSetController {  
	
	private static final Logger logger = LoggerFactory.getLogger(ExtentionSetController.class);
    
    @RequestMapping("/load")  
    public String getProps(ModelMap modelMap) throws IOException{	
    	logger.info("into load controller");
    	
		modelMap.addAttribute("extentionModelList", ExtentionAttributeUtil.getExtentionList());	
		Locale locale = LocaleUtil.getLocale();
		
		return "/config/configExtentionAttr"; 
    }
    
    @RequestMapping(value = "set", method = {RequestMethod.POST },produces={"text/html;charset=UTF-8;","application/json;"})
    @ResponseBody
    public String setProps(@RequestBody List<ExtentionModel> list) throws IOException{	
    	logger.info("into set controller");
    	logger.info("size"+list.size());
    	for(ExtentionModel em:list){
    		logger.info(em.getBbClsName());
    		logger.info(em.getBbAttribute());
    		logger.info(em.getModelClsName());
    		logger.info(em.getModelAttribute());
    	}
    	ExtentionAttributeUtil.setAndPersistExtentionList(list);

		return ""; 
    }

}  
